# 使用基础镜像
FROM centos:centos7.9.2009

# 禁用交互式提示
ENV DEBIAN_FRONTEND=noninteractive


# 设置工作目录为 /app
WORKDIR /app

# 清楚无效源
RUN mkdir /etc/yum.repos.d/backup
RUN mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/backup/

COPY ./CentOS-Vault.repo /etc/yum.repos.d/

# 预先导入 GPG 密钥
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

RUN yum makecache && \
    yum update -y --exclude=centos-release && \
    yum clean all

# 安装常用工具和依赖
RUN yum install epel-release -y
RUN yum install -y pcre-devel zlib-devel openssl openssl-devel gcc gcc-c++ kernel-devel libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libpng libpng-devel libmcrypt-devel wget which unzip
RUN yum install -y gcc make libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel sqlite-devel libzip-devel oniguruma-devel readline-devel
RUN yum install -y libxml2 libxml2-devel
RUN yum install -y openssl openssl-devel
RUN yum install -y bzip2 bzip2-devel
RUN yum install -y curl curl-devel
RUN yum install -y libpng libpng-devel
RUN yum install -y libmcrypt libmcrypt-devel
RUN yum install -y freetype freetype-devel
RUN yum install -y mariadb-server mariadb mariadb-devel 


# nginx
COPY ./nginx-1.17.9.tar.gz /usr/local/src/
COPY ./nginx-http-concat-master.zip /usr/local/src/
RUN cd /usr/local/src/ && tar -xzvf nginx-1.17.9.tar.gz
RUN cd /usr/local/src/ && unzip nginx-http-concat-master.zip


RUN cd /usr/local/src/nginx-1.17.9 && ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=../nginx-http-concat-master && \
	make && \
	make install
RUN ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
RUN ln -s /usr/local/nginx/conf /etc/nginx
RUN ln -s /usr/local/nginx/logs/nginx.pid /var/run/nginx.pid
RUN ln -s /usr/local/nginx/logs /var/log/nginx
RUN nginx -v



# php7.1.33
COPY ./php-7.1.33.tar.bz2 /usr/local/src/
RUN cd /usr/local/src/ && tar -jxvf php-7.1.33.tar.bz2
RUN cd /usr/local/src/php-7.1.33 && ./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--enable-fpm \
--with-pdo-mysql=/usr/bin/mysql \
--with-mysqli=/usr/bin/mysql_config \
--with-openssl \
--with-pcre-jit \
--with-zlib \
--with-zlib-dir \
--enable-bcmath \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--with-gd \
--with-freetype-dir=/usr/ \
--with-png-dir=/usr/include \
--with-jpeg-dir=/usr/include \
--with-gettext \
--with-mhash \
--enable-intl \
--with-mysqli \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-readline \
--enable-sockets \
--enable-mbstring \
--with-libxml-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--with-pear && \
	make && \
	make install
RUN cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
RUN cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
RUN ln -s /usr/local/php7/sbin/php-fpm /usr/local/bin/php-fpm
RUN ln -s /usr/local/php7/bin/php /usr/local/bin/php



# 设置启动命令
# CMD echo "Starting Weyon Web..." && php-fpm && nginx 
# CMD ["sh", "-c", "echo 'Starting Weyon Web...' && php-fpm && nginx && tail -f /dev/null"]

# 复制 start.sh 脚本到容器中
COPY ./start.sh /usr/local/bin/start.sh

# 设置脚本可执行权限
RUN chmod +x /usr/local/bin/start.sh

# 设置启动入口
ENTRYPOINT ["/usr/local/bin/start.sh"]